import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import entity.BidderRef;
import entity.Player;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author ml
 * @create 2017-08-18--14:21
 */
public class CheckNum {
    public static void main(String[] args) {

        String url="http://139.196.174.134/services/captcha/getCompetitionResults?type=a1&_=1503037821806";
        try {
            Connection.Response document= Jsoup.connect(url)
                    .header("Accept", "*/*")
                    .header("Accept-Encoding", "gzip, deflate")
                    .header("Accept-Language","zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
                    .header("Content-Type", "application/json;charset=UTF-8")
                    .header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0")
                    .timeout(10000).ignoreContentType(true).execute();
            System.out.println(document.toString());
            String body = document.body();
            JSONObject jsonObject= JSON.parseObject(body);
            JSONObject data=jsonObject.getJSONObject("data");
            JSONArray results=data.getJSONArray("competitionAggregatedResults");
            List<Player> playerList=JSON.parseArray(results.toJSONString(),Player.class);
            StringBuilder sb=null;
            int i=0;
            for(Player player:playerList){
                BidderRef bidderRef=player.getBidderRef();
                sb=new StringBuilder();
                sb.append(++i+"  ").append("姓名:").append(bidderRef.getName()).append(" QQ:").append(bidderRef.getQq())
                        .append(" 手机号:").append(bidderRef.getMobile()).append(" 学校:").append(bidderRef.getUniversityRef()
                        .getName()).append(" 最快时间:").append(player.getAggregatedResult().getMinDuration()/1000.0)
                        .append(" TA的上线:").append(bidderRef.getLeaderRef()==null?"马林":bidderRef.getLeaderRef().getName()).append(" 最后更新时间：")
                .append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(bidderRef.getUpdatedAt()));


                System.out.println(sb.toString());

            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
